package cn.jhz.learn.blog.config;


import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration.Dynamic;

import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.filter.FormContentFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * @author asus
 *
 */
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		// TODO Auto-generated method stub
//		return new Class<?>[] { RootConfig.class };
		return null;
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		// TODO Auto-generated method stub
		 return new Class<?>[] { WebConfig.class, RootConfig.class};
	}

	@Override
	protected String[] getServletMappings() {
		// TODO Auto-generated method stub
		return new String[] { "/" };
	}

	@Override
	protected Filter[] getServletFilters() {
		DelegatingFilterProxy shiroFilter = new DelegatingFilterProxy("shiroFilter");
		FormContentFilter formContentFilter = new FormContentFilter();
		formContentFilter.setBeanName("formContentFilter");
		shiroFilter.setTargetFilterLifecycle(true);
		shiroFilter.setBeanName("shiroFilter");
		return new Filter[]{formContentFilter,shiroFilter};
	}
	@Override
	protected void customizeRegistration(Dynamic registration) {
		registration.setMultipartConfig(
				new MultipartConfigElement(
						"/",
						33554432,
						167772160,
						0));
	}

}
